CC=gcc
CFLAGS+=-Wall
LIBPATH=../../../../..
INCLS=-I$(LIBPATH)/include
LIBS_DEBUG=-L$(LIBPATH)/lib -lsoar_g -lpthread
LIBS=-L$(LIBPATH)/lib -lsoar -lpthread

OBJS=main.o monitor.o listener.o worker.o
SERVER=$(shell awk '/SERVER *=/ { split($$0,arr,"="); gsub(" ","",arr[2]); print arr[2]; }' ../server.cnfg)
SERVER_DEBUG=$(SERVER)_debug

default : debug

all : debug release

debug : $(SERVER_DEBUG)

$(SERVER_DEBUG) : $(OBJS)
	$(CC) $(CFLAGS) $(INCLS) -o $@ $^ $(LIBS_DEBUG)
	chmod 744 $@

$(OBJS) : %.o : %.c
	$(CC) $(CFLAGS) -D_MY_DEBUG -g $(INCLS) -c -o $@ $<

release : $(SERVER)

$(SERVER) : $(OBJS:%.o=%.c)
	$(CC) $(CFLAGS) -O3 $(INCLS) -o $@ $^ $(LIBS)
#	$(CC) $(CFLAGS) -g $(INCLS) -o $@ $^ $(LIBS_DEBUG)
	chmod 744 $@

clean :
	rm -f core* *.log $(OBJS) $(SERVER) $(SERVER_DEBUG)
